my_onload();
var out_print_val = "";
var screen_elem_obj = document.getElementsByClassName("screen").item(0);
var curr_cal_result = 0;

var OPER_TYPE_NULL = 0;
var OPER_TYPE_ADD = 1;
var OPER_TYPE_MINUS = 2;
var OPER_TYPE_MULTI = 3;
var OPER_TYPE_DIV = 4;
var OPER_TYPE_EQAL = 5;

var curr_oper_type = OPER_TYPE_NULL;



function my_onload() {

	var clear_elem_obj = document.getElementsByClassName("clear").item(0);
	var keys_num_list = document.getElementsByClassName("keys-num");
	var keys_oper_list = document.getElementsByClassName("operator");
	var eqal_elem_obj = document.getElementsByClassName("eval").item(0);

	for (var i = 0; i < keys_num_list.length; i++) {
		keys_num_list[i].onclick = function() {
			keys_num_onclick(this);
		}
	}

	clear_elem_obj.onclick = function() {
		clear_key_onclick();
	}

	eqal_elem_obj.onclick = function() {
		equal_key_onclick(this);
	}

	for (var i = 0; i < keys_oper_list.length; i++) {
		keys_oper_list[i].onclick = function() {
			operator_key_onclick(this);
		}
	}
}

function equal_key_onclick(curr_obj) {
	console.log("equal_key_onclick");
	if (curr_oper_type == OPER_TYPE_ADD) {
		curr_cal_result += parseInt(out_print_val);
	} else if (curr_oper_type == OPER_TYPE_MINUS) {
		curr_cal_result -= parseInt(out_print_val);
	} else if (curr_oper_type == OPER_TYPE_MULTI) {
		curr_cal_result *= parseInt(out_print_val);
	} else if (curr_oper_type == OPER_TYPE_DIV) {
		curr_cal_result *= parseInt(out_print_val);
	}

	curr_oper_type = OPER_TYPE_EQAL;

	out_print_val = curr_cal_result.toString();
	screen_elem_obj.innerHTML = out_print_val;

}

function operator_key_onclick(curr_obj) {
	console.log("operator_key_onclick");
	if (curr_obj.innerHTML == "+") {
		curr_oper_type = OPER_TYPE_ADD;
	} else if (curr_obj.innerHTML == "-") {
		curr_oper_type = OPER_TYPE_MINUS;
	} else if (curr_obj.innerHTML == "*") {
		curr_oper_type = OPER_TYPE_MULTI;
	} else if (curr_obj.innerHTML == "/") {
		curr_oper_type = OPER_TYPE_DIV;
	}
	curr_cal_result = parseInt(out_print_val);
	out_print_val = "";
	screen_elem_obj.innerHTML = out_print_val;
}

function clear_key_onclick() {
	out_print_val = "";
	curr_cal_result = 0;
	screen_elem_obj.innerHTML = out_print_val;
}

function keys_num_onclick(curr_key) {

	out_print_val += curr_key.innerHTML;
	screen_elem_obj.innerHTML = out_print_val;

}